package com.gitee.cnlongs.cnlongmq.server.threads.message;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gitee.cnlongs.cnlongmq.basic.entitiy.request.CnLongMqMessage;
import com.gitee.cnlongs.cnlongmq.basic.entitiy.response.CnLongMqResponse;
import com.gitee.cnlongs.cnlongmq.basic.enums.CnLongMqDataSync;
import com.gitee.cnlongs.cnlongmq.server.handler.LongMqRequest;

/**
 * 系统名称：HandlerLongMqMessage
 * 模块名称：
 * 模块描述：多线程异步处理消息
 * 功能列表：
 * 模块作者：zouyong
 * 开发时间：2019年4月16日 下午3:29:08
 * 模块路径：com.gitee.cnlongs.cnlongmq.server.threads.message.HandlerLongMqMessage
 */
public class HandlerLongMqMessage extends Thread {

	private static final Logger logger = (Logger) LoggerFactory.getLogger(HandlerLongMqMessage.class);
	
	private CnLongMqMessage mqMessage;
	
	private CnLongMqResponse message;
	
	public HandlerLongMqMessage(CnLongMqMessage mqMessage, CnLongMqResponse message) {
		this.mqMessage = mqMessage;
		this.message = message;
	}
	
	@Override
	public void run() {
		try {
			// 调用业务系统方法，执行ACK确认
			LongMqRequest.handlerMqMessage(mqMessage, message);
		}
		catch (Exception e) {
			logger.error("内部类-多线程-执行ACK确认异常：" + e.getMessage());
			try {
				mqMessage.setReqType(CnLongMqDataSync.noticeAckResult.name());
				LongMqRequest.launchSendMessage(mqMessage);
			} catch(Exception ec) {
				logger.error("执行异常的ACK确认通知失败，异常原因是：" + ec.getMessage());
			}
		}
	}
	
}
